﻿@page "/index"
@using CardMaker.Library.Services

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />
<input type="text" @bind-value="@text" />
<button @onclick="LoadLocalImage">确定</button>
<button @onclick="SelectLocalImage">选择</button>
<img style="max-width:300px;max-height:300px;" src="@imageUrl" />



@code {
    [Inject]
    private ILocalImageService LocalImageService { get; set; }
    private string text;
    private string imageUrl;
    private string path;
    private async Task LoadLocalImage() {
        await LocalImageService.RevokeUrl(path);
        path = text;
        imageUrl = await LocalImageService.ToUrl(path);
    }
    private async Task SelectLocalImage()
    {
        FileResult photo = await MediaPicker.Default.PickPhotoAsync();
        if (photo == null)
        {
            return;
        }
        if (string.IsNullOrEmpty(photo.FullPath))
        {
            return;
        }
        await LocalImageService.RevokeUrl(path);
        path = text = photo.FullPath;
        imageUrl = await LocalImageService.ToUrl(path);
    }
}